/**
 * @Date 2025/1/8 11:31
 * @Created by 衡盛永
 */

package org.example.deploy.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.deploy.mapper.SysPermissionMapper;
import org.example.deploy.pojo.SysPermission;
import org.example.deploy.service.SysPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class SysPermissionServiceImpl extends ServiceImpl<SysPermissionMapper, SysPermission> implements SysPermissionService {

    @Autowired
    private SysPermissionMapper sysPermissionMapper;

    @Override
    public List<SysPermission> getPermissionsByRoleId(Integer roleId) {
        List<Integer> permissionIdsByRoleId = sysPermissionMapper.getPermissionIdsByRoleId(roleId);
        // 如果没有找到权限 ID，返回空列表
        if (permissionIdsByRoleId == null || permissionIdsByRoleId.isEmpty()) {
            return Collections.emptyList();  // 返回一个空的列表，避免 null
        }
        return sysPermissionMapper.selectBatchIds(permissionIdsByRoleId);
    }
}
